package com.fms.controllers;

import com.fms.model.BKCashAdvanceRegisterModel;
import com.fms.dao.BKCashAdvanceRegisterDAO;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;

public class BKCashAdvanceRegister extends WebPage {
	
	private Model entryNoModel = new Model();
	private Model orgIdModel = new Model();
	private Model dateModel = new Model();
	private Model rcvNoModel =  new Model();
	private Model requestingOfficerModel = new Model();
	private Model purposeModel = new Model() ;
	private Model amountModel = new Model();
	private Model statusModel = new Model();
	
	public BKCashAdvanceRegister(){
		
		Form bkCashAdvanceRegisterForm = new Form ("bkCashAdvanceRegisterForms");
		
		TextField entryNo = new TextField("entryNo", entryNoModel);
		entryNo.setRequired(true);
		bkCashAdvanceRegisterForm.add(entryNo);
		
		TextField orgId = new TextField("orgId", orgIdModel);
		orgId.setRequired(true);
		bkCashAdvanceRegisterForm.add(orgId);
		
		TextField date = new TextField("date", dateModel);
		date.setRequired(true);
		bkCashAdvanceRegisterForm.add(date);
		
		TextField rcvNo = new TextField("rcvNo", rcvNoModel);
		rcvNo.setRequired(true);
		bkCashAdvanceRegisterForm.add(rcvNo);
		
		TextField requestingOfficer = new TextField("requestingOfficer", requestingOfficerModel);
		requestingOfficer.setRequired(true);
		bkCashAdvanceRegisterForm.add(requestingOfficer);
		
		TextField purpose = new TextField("purpose", purposeModel);
		purpose.setRequired(true);
		bkCashAdvanceRegisterForm.add(purpose);
		
		TextField amount = new TextField("amount", amountModel);
		amount.setRequired(true);
		bkCashAdvanceRegisterForm.add(amount);
		
		TextField status = new TextField("status", statusModel);
		status.setRequired(true);
		bkCashAdvanceRegisterForm.add(status);
		
		add(bkCashAdvanceRegisterForm);
		
		Button bkCashAdvanceRegisterAdd = new Button ("bkCashAdvanceRegisterAdd"){
			
			public void onSubmit(){
				
				String nentryNo = (String) entryNoModel.getObject();
				String norgId = (String) orgIdModel.getObject();
				String date = (String) dateModel.getObject();
				String nrcvNo = (String) rcvNoModel.getObject();
				String requestingOfficer = (String) requestingOfficerModel.getObject();
				String purpose = (String) purposeModel.getObject();
				String namount = (String) amountModel.getObject();
				String status = (String) statusModel.getObject();
				
				int entryNo = Integer.parseInt(nentryNo);
				int orgId = Integer.parseInt(norgId);
				int rcvNo = Integer.parseInt(nrcvNo);
				float amount = Float.valueOf(namount);
				
				BKCashAdvanceRegisterModel bkCAR = new BKCashAdvanceRegisterModel(entryNo, orgId, date, rcvNo,
						requestingOfficer, purpose, amount, status);
				
				BKCashAdvanceRegisterDAO bkCARDAO = new BKCashAdvanceRegisterDAO ();
				bkCARDAO.insert(bkCAR);
			}
		
		};
	
	}

}
